<template>
  <el-form
    :model="ruleForm2"
    status-icon
    :rules="rules2"
    ref="ruleForm2"
    label-width="100px"
    class="demo-ruleForm"
  >
    <el-form-item label="用户名" prop="name">
      <el-input
        type="text"
        v-model="ruleForm2.name"
        auto-complete="off"
      ></el-input>
    </el-form-item>

    <el-form-item label="密码" prop="pass">
      <el-input
        type="text"
        v-model="ruleForm2.pass"
        auto-complete="off"
      ></el-input>
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="submitForm('ruleForm2')"
        >登录</el-button
      >
      <el-button @click="resetForm('ruleForm2')">重置</el-button>
    </el-form-item>
  </el-form>
</template>    
<script>
export default {
  data() {
    //   用户名
    var validateName = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入名字"));
      } else {
        if (this.ruleForm2.name !== "") {
          this.$refs.ruleForm2.validateField("name");
        }
        callback();
      }
    };
    //密码

    var validatePass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"));
      } else {
        if (this.ruleForm2.pass !== "") {
          this.$refs.ruleForm2.validateField("pass");
        }
        callback();
      }
    };

    return {
      ruleForm2: {
        name: "",
        pass: "",
      },
      rules2: {
        name: [{ validator: validateName, trigger: "blur" }],
        pass: [{ validator: validatePass, trigger: "blur" }],
      },
    };
  },
  methods: {

      //登录成功后把token  把token 存储到本地缓存以及vuex  
      
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert("submit!");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },

    
  },


// mounted() {
//     let isFlag=localStorage.getItem('isLogin')
//     if(isFlag==undefined|| isFlag=='false') {
        
//     } 

// }

};
</script>

<style scoped>
</style>